"""
# Arithmetic of Complex Number
@ Eugene.Complexa.Ares
! MIT License
~ Assume that we have two complex number, a=1+5i, b=5-4i, where i is the imaginary unit. Please implement a class (in Python) that supports the arithmetic (addition, subtraction, multiplication and division) of complex number, where we can directly use binary operator (+, -, *, /) to finish corresponding calculation. 
"""



class ComplexNum:
  
  def __init__(self, a, b):
    self.a = a
    self.b = b
  
  def __repr__(self):
    return "{}+{}i".format(self.a,self.b)
  #+
  def __add__(self, other):
    obj = ComplexNum(self.a + other.a, self.b + other.b)
    return obj
  #-
  def __sub__(self,other):
    obj = ComplexNum(self.a - other.a, self.b - other.b)
    return obj
  #*
  def __mul__(self, other):
    obj = ComplexNum(self.a * other.a - self.b * other.b, self.a * other.b + self.b * other.a)
    return obj
  #/
  def __truediv__(self, other):
    #print(other.a,other.b)
    numdiv = other.a ** 2 + other.b ** 2
    #assert numdiv != 0:
    #print(numdiv)
    if numdiv == 0:
      #print('error, 0 cannot be divided')
      return 'inf'
    else:
      x = (self.a * other.a + self.b * other.b) / numdiv
      y = (self.b * other.a - self.a * other.b) / numdiv
      obj = ComplexNum(x, y)
      return obj
    

if __name__ == "__main__":
  print(ComplexNum(1,2)+ComplexNum(3,4))
  print(ComplexNum(1,2)-ComplexNum(3,4))
  print(ComplexNum(1,2)*ComplexNum(3,4))
  print(ComplexNum(1,2)/ComplexNum(3,4))
  # 0 test
  print(ComplexNum(1,2)/ComplexNum(0,0))